package com.yohann.boot.service.impl;

import com.yohann.boot.service.RabbitMqService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Yeung Wah
 * @since 2021/9/12
 */
@Service
public class RabbitMqServiceImpl implements RabbitMqService {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void sendMessage(String exchangeName, String routingKey, String message) {
        rabbitTemplate.convertAndSend(exchangeName, routingKey, message);
    }

    @Override
    public void sendMessage(String exchangeName, String routingKey, String message, String ttl) {
        rabbitTemplate.convertAndSend(exchangeName, routingKey, message, param -> {
            param.getMessageProperties().setExpiration(ttl);
            return param;
        });
    }
}